/*
题目链接:https://leetcode.cn/problems/rabbits-in-forest/description/?envType=daily-question&envId=2025-04-20
*/
//题解代码:
class Solution {
public:
    int numRabbits(vector<int>& answers) {
        sort(answers.begin(),answers.end());
        int n = answers.size();
        int cnt = 1;
        int ans = 0;
        for(int i=1;i<n;++i){
            if(answers[i] != answers[i-1]){
                ans += (answers[i-1]+1) * ((cnt+answers[i-1])/(answers[i-1]+1));
                cnt = 1;
            }else{
                ++cnt;
            }
        }
        ans += (answers[n-1]+1) * ((cnt+answers[n-1])/(answers[n-1]+1));
        return ans;
    }
};
